package com.mzy.linear_struct.hot100.动态规划;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: mizy3
 * @Date: 2024/09/12/下午4:16
 * @Description:
 */
public class Pro5最长回文子串 {
    public String longestPalindrome(String s) {
        // dp[i][j] 表示当前位置的的最长回文子串长度
        int[][] dp = new int[s.length() + 1][s.length() + 1];
        for (int i = 0; i <= s.length(); i++) {
            dp[0][i] = 1;
        }
        for (int i = 0; i <= s.length(); i++) {
            dp[i][0] = 1;
        }
        for (int i = 1; i < dp.length; i++) {
            for (int j = 1; j < dp[i].length; j++) {
                if (s.charAt(i - 1) == s.charAt(j - 1)) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }
            }

        }
        for (int i = 0; i < dp.length; i++) {
            for (int j = 0; j < dp[i].length; j++) {
                System.out.print(dp[i][j] + " ");
            }
            System.out.println();
        }
        return "";
    }

    public static void main(String[] args) {
        System.out.println(new Pro5最长回文子串().longestPalindrome("babad"));
    }
}
























